﻿using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using TemplateFoundation.WebControls.PropertyControls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TemplateFoundation.Tests
{
    
    
    /// <summary>
    ///This is a test class for PropertyStringControlTest and is intended
    ///to contain all PropertyStringControlTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PropertyStringControlTest : PropertyStringControl
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void TestRenderWithEmptyControlsCollection()
        {
            Controls.Clear();

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var tw = new HtmlTextWriter(sw))
                {
                    Render(tw);

                    Assert.AreEqual(string.Empty, sb.ToString(), "Expected an empty string to be rendered");
                }
            }
        }

        [TestMethod]
        public void TestRenderWithEmptyControlsAndContainerElementSetCollection()
        {
            Controls.Clear();

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var tw = new HtmlTextWriter(sw))
                {
                    Render(tw);

                    Assert.AreEqual(string.Empty, sb.ToString(), "Expected an empty string to be rendered");
                }
            }
        }

        [TestMethod]
        public void TestRenderWithSingleParagraphInControlsCollection()
        {
            Controls.Clear();

            var outerSpan = new HtmlGenericControl("span");

            outerSpan.Controls.Add(new LiteralControl("<p>This is a paragraph.</p>"));

            Controls.Add(outerSpan);

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var tw = new HtmlTextWriter(sw))
                {
                    Render(tw);

                    Assert.AreEqual("<p>This is a paragraph.</p>", sb.ToString(), "Expected a single P element");
                }
            }
        }

    }
}
